﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Base;
using UtilZ.Dotnet.Ex.Log;

namespace LinuxSourcePkDownlader
{
    internal abstract class PkDownladerAbs : IPkDownlader
    {

        public string Name { get; private set; }

        public PkDownladerAbs(string name)
        {
            this.Name = name;
        }

        public void Download(ThreadExPara threadPara, string dir)
        {
            try
            {
                this.PrimitiveDownload(threadPara, dir);
            }
            catch (Exception ex)
            {
                Loger.Error(ex);
            }

        }

        protected abstract void PrimitiveDownload(ThreadExPara threadPara, string dir);

        protected HttpClient CreateHttpClient()
        {
            var httpClient = new HttpClient();
            httpClient.Timeout = TimeSpan.FromSeconds(300);
            return httpClient;
        }

        private bool _disposed = false;
        public void Dispose()
        {
            if (this._disposed)
            {
                return;
            }
            this._disposed = true;

            this.Dispose(true);
        }

        protected virtual void Dispose(bool disposing)
        {

        }
    }
}
